﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;
using GMS.Utils;
using GMS.Model;
using GMS.BLL;
using GMS.Web.CommonPage;
using System.Data;
using Maticsoft.DBUtility;
using System.Drawing;

public partial class public_chart1 : System.Web.UI.Page
{
    DbHelper db = new DbHelper();
    //ChartCtr chartmodel = new ChartCtr();
    DataSet ds = new DataSet();
    //ChartCtrAccessBLL chartdal = new ChartCtrAccessBLL();
    //TabInfoAccessBLL dal = new TabInfoAccessBLL();
    TabInfo model = new TabInfo();
    ComOperate CDO = new ComOperate();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           string tabcode = Session["tabcode"].ToString();
           if ((int)EnumHelper.E_DbType.DB_ACCESS == PubConstant.GetDBType())
           {
               TabInfoAccessBLL tabinfobll = new TabInfoAccessBLL();
               ChartCtrAccessBLL charctrbll = new ChartCtrAccessBLL();
               model = tabinfobll.GetModel(tabcode);

               if (model != null)
               {
                   int a = model.AUTOID;
                   ds = charctrbll.GetX(a);
                   xcolumn.DataSource = ds;
                   xcolumn.DataTextField = "SeltColumn";
                   xcolumn.DataBind();
                   ds = charctrbll.GetY(a);
                   ycolumn.DataSource = ds;
                   ycolumn.DataTextField = "SeltColumn";
                   ycolumn.DataBind();
               }
           }
           else if ((int)EnumHelper.E_DbType.DB_SQL == PubConstant.GetDBType())
           {
               TabInfoAccessBLL tabinfobll = new TabInfoAccessBLL();
               ChartCtrAccessBLL charctrbll = new ChartCtrAccessBLL();
               model = tabinfobll.GetModel(tabcode);
               if (model != null)
               {
                   int a = model.AUTOID;
                   ds = charctrbll.GetX(a);
                   xcolumn.DataSource = ds;
                   xcolumn.DataTextField = "SeltColumn";
                   xcolumn.DataBind();
                   ds = charctrbll.GetY(a);
                   ycolumn.DataSource = ds;
                   ycolumn.DataTextField = "SeltColumn";
                   ycolumn.DataBind();
               }
           }
           else if ((int)EnumHelper.E_DbType.DB_ORACLE == PubConstant.GetDBType())
           {
               TabInfoOraBLL tabinfobll = new TabInfoOraBLL();
               ChartCtrOraBll charctrbll = new ChartCtrOraBll();
               model = tabinfobll.GetModel(tabcode);
               if (model != null)
               {
                   int a = model.AUTOID;
                   ds = charctrbll.GetX(a);
                   xcolumn.DataSource = ds;
                   xcolumn.DataTextField = "SeltColumn";
                   xcolumn.DataBind();
                   ds = charctrbll.GetY(a);
                   ycolumn.DataSource = ds;
                   ycolumn.DataTextField = "SeltColumn";
                   ycolumn.DataBind();
               }
           }
           else
               return ;
         
          
           
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       // Chart1.Series["Series1"].IsValueShownAsLabel = true;
        Chart1.Width = 555;
        Chart1.Height = 555;
        Chart1.ChartAreas["ChartArea1"].AxisX.LineWidth = 2;
        Chart1.ChartAreas["ChartArea1"].AxisY.LineWidth = 2;
        Chart1.ChartAreas["ChartArea1"].AxisX.LineColor = Color.Blue;
        Chart1.ChartAreas["ChartArea1"].AxisY.LineColor = Color.Red;
        //Chart1.ChartAreas["ChartArea1"].AxisX.Title = xcolumn.SelectedValue.ToString();
        //Chart1.ChartAreas["ChartArea1"].AxisY.Title = ycolumn.SelectedValue.ToString();
        //switch (charttype.SelectedValue.ToString())
        //{ 
        //    case "1":
        //      break;
        //    case "2":
        //       Chart1.Series["Series1"].ChartType=SeriesChartType.Line;break;
        //    case "3":
        //       Chart1.Series["Series1"].ChartType = SeriesChartType.Pie;break;
        //}
        if ((int)EnumHelper.E_DbType.DB_ACCESS == PubConstant.GetDBType())
        {
            ChartCtrAccessBLL bll = new ChartCtrAccessBLL();
            ds = bll.GetTable(Session["tabcode"].ToString());
        }
        else if ((int)EnumHelper.E_DbType.DB_SQL == PubConstant.GetDBType())
        {
            ChartCtrAccessBLL bll = new ChartCtrAccessBLL();
            ds = bll.GetTable(Session["tabcode"].ToString());
        }
        else if ((int)EnumHelper.E_DbType.DB_ORACLE == PubConstant.GetDBType())
        {
            ChartCtrOraBll bll = new ChartCtrOraBll();
            ds = bll.GetTable(Session["tabcode"].ToString());
        }
        else
            return ;
        
      // ds= CDO.GetComData(Session["tabcode"].ToString(), null, 0,22, null, null/*OP.CitySelected*/);
       Chart1.DataSource = ds;
       int count = 0;
       foreach (ListItem item in ycolumn.Items)
       {
           if (item.Selected == true)
           {
               count++;
               if (count >= 2 && charttype.SelectedValue.ToString() == "3")
               {
                   Response.Write("<script>alert('不能为饼状图')</script>"); break;
               }
               string name = item.ToString();
               Chart1.Series.Add(name);
               Chart1.Series[name].IsValueShownAsLabel = true;
               Chart1.ChartAreas["ChartArea1"].AxisX.Title = xcolumn.SelectedValue.ToString();
               //Chart1.ChartAreas["ChartArea1"].AxisY.Title = name;
               switch (charttype.SelectedValue.ToString())
               {
                   case "1":
                       break;
                   case "2":
                       Chart1.Series[name].ChartType = SeriesChartType.Line; break;
                   case "3":
                         Chart1.Series[name].ChartType = SeriesChartType.Pie; break;
               }

               Chart1.Series[name].XValueMember = xcolumn.SelectedValue.ToString();
               Chart1.Series[name].YValueMembers = item.ToString();
           }
       }
      
       Chart1.DataBind();

    }
}